package com.xdjk.networkdemo.net.db;

import com.xdjk.networkdemo.javagen.BaseDao;
import com.xdjk.networkdemo.javagen.DaoSession;
import com.xdjk.networkdemo.javagen.DownInfoDao;
import com.xdjk.networkdemo.net.bean.DownInfo;

import org.greenrobot.greendao.query.QueryBuilder;

import java.util.List;

/**
 * Created by zhanghs on 2017/8/18.
 */

public class DBUtils {
    private static DBUtils dbUtils;
    private DaoSession mDaoSession;
    private DownInfoDao downInfoDao;

    public DBUtils() {
    }

    public static DBUtils getInstance() {
        if (null == dbUtils) {
            synchronized (DBUtils.class) {
                if (null == dbUtils) {
                    dbUtils = new DBUtils();
                    dbUtils.mDaoSession = BaseDao.getDaoSession();
                    dbUtils.downInfoDao = dbUtils.mDaoSession.getDownInfoDao();
                }
            }
        }
        return dbUtils;
    }

    public void update(DownInfo downInfo) {
        downInfoDao.update(downInfo);
    }

    public void save(DownInfo info) {
        downInfoDao.insert(info);
    }
    public List<DownInfo> queryDownAll() {
        QueryBuilder<DownInfo> qb = downInfoDao.queryBuilder();
        return qb.list();
    }

}
